import pygame
import time
import random
N=int(input("行数"))
w=int(input("大小"))
s=int(input("1.是.2.不是"))
x_f=w*N
y_f=w*N
pygame.init()
screen=pygame.display.set_mode([x_f,y_f])
screen.fill([255,255,255])
def erweima(x,y):
    pygame.draw.rect(screen,[0,0,0],[x,y,5*w,5*w],0)
    pygame.draw.rect(screen,[255,255,255],[x+w,y+w,w*3,3*w],0)
    pygame.draw.rect(screen,[0,0,0],[x+2*w,y+2*w,w,w],0)
def erweimaa(t):
    i=0
    while i<N:
        j=0
        while j<N:
            a_1=random.randint(0,1)
            a_2=random.randint(0,1)
            a_3=random.randint(0,1)
            if a_1==1:
                a_1=255
            if a_2==1:
                a_2=255
            if a_3==1:
                a_3=255
            pygame.draw.rect(screen,[a_1,a_1,a_1],[i*w,j*w,w,w],0)
            j+=1
        i+=1
    erweima(0,0)
    erweima(x_f-5*w,0)
    erweima(0,y_f-5*w)
    pygame.display.flip()
if s==1:
    t=0
    aaa=0
    while t<10:
        erweimaa(1)
        time.sleep(2)
        t=t+1
        aaa=aaa+1
        print(f"这是第{aaa}个")
    running=False
    t=t+10
if s==2:
    erweimaa(1)
    running=True
while running:
    for event in pygame.event.get():
        # print(event)
        if event.type == pygame.QUIT:
            running=False
pygame.quit()
